﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SoccerSimulator5000
{
    public partial class SimRoundForm : Form
    {
        Round round;
        private Button buttonSimulate = new Button();
        public SimMatchForm simMatch = new SimMatchForm(0,0);

        public SimRoundForm( Round round )
        {
            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            buttonSimulate.Location = new Point(50, 500);
            buttonSimulate.Size = new Size(100, 50);
            buttonSimulate.Text = "Simulate";
            buttonSimulate.Click += new EventHandler(this.buttonSimulate_Click);

            this.round = round;
            this.Controls.Add(buttonSimulate);

        }

        private void buttonSimulate_Click(object sender, EventArgs e)
        {
            simMatch.matchNumber = -1;
            foreach (var Match in round.round)
            {
                simMatch.matchNumber++;
                if ((Match.homeTeam.name == Game.player.playerTeam.name) || (Match.awayTeam.name == Game.player.playerTeam.name))
                {
                    simMatch.match = Match;
                    simMatch.round = Match.roundNumber - 1;
                    simMatch.ShowDialog();
                }
                else
                {
                    Match.PlayMatch();
                }
            }
            buttonSimulate.Enabled = false;
            this.Invalidate();
            Game.season.seasonStandings.SortStandings();
        }

        private void SimRoundForm_Paint(object sender, PaintEventArgs e)
        {
            System.Drawing.Graphics g = e.Graphics;

            Game.date.Draw(10, 10, g);
            round.Draw(15, 40, g);
        }

        
    }
}
